Skip to content

Fix OSC 11 background color query leaking after --version/--help - #1798

Open
YrFnS wants to merge 1 commit into
CodebuffAI:mainfrom
YrFnS:fix/osc-11-leak-on-version-help
Open

YrFnS wants to merge 1 commit into
CodebuffAI:mainfrom
YrFnS:fix/osc-11-leak-on-version-help

Conversation

@YrFnS

@YrFnS YrFnS commented Dec 4, 2026

Copy link
Copy Markdown

Fixes #1743.

Summary

Running freebuff --version or freebuff --help (and NO_COLOR=1 freebuff --version) left the terminal's OSC 11 background-color reply (e.g. 11;rgb:2c2c/3737/4646) sitting in the shell's input buffer.

The cause: OSC 10/11 terminal theme detection started before CLI flags were parsed. For early-exit commands, Commander printed the version/help and the process exited before the terminal's reply could be read, so the reply was never consumed and leaked into the next shell prompt.

This change skips the OSC query entirely for those invocations (and when NO_COLOR is set), falling back to the existing synchronous env/fallback theme evidence. No query is written to the TTY and stdin is not switched to raw mode, so there is nothing left for the shell to read.

Changes

  • cli/src/utils/terminal-color-detection.ts — terminalSupportsOSC() returns false when NO_COLOR is set or when process.argv contains --version/-v/--help/-h.
  • cli/src/index.tsx — oscQuerySupported is gated the same way, so detectTerminalTheme() is not called for those invocations.
  • cli/src/types/env.ts, cli/src/utils/env.ts — add NO_COLOR to CliEnv and getCliEnv().

Testing

  • bun test cli/src/utils/__tests__/terminal-color-detection.test.ts → 70 pass, 0 fail.
  • Verified terminalSupportsOSC returns false for --version and NO_COLOR=1, true otherwise.
  • Typecheck of the touched files introduced no new errors.
  • Not reproduced end-to-end in a real terminal, so the leak itself is unverified here.

Scope

Touches only cli/ and CLI env/types; no backend, billing, deployment, or secret-management paths. Single focused fix.

Skip the terminal OSC color query for non-interactive early-exit
invocations (--version/-v/--help/-h) and when NO_COLOR is set, so the
terminal's reply is never left in the shell input buffer.
@codebuff-team

Copy link
Copy Markdown
Contributor

Good catch on the root cause — early-exit commands (--version/--help) print and exit before the OSC 11 reply can be consumed, leaking it into the shell. Skipping the query for NO_COLOR and early-exit paths is a sensible instinct.

A few concerns on the implementation:

  1. Flag detection is too broad. process.argv.some(arg => arg === '-v' || ...) scans the entire argv array, not just the top-level command. If a subcommand takes a -v/-h flag for something unrelated (verbose logging, etc.), this will silently disable OSC detection even though the process won't exit early. You'd be more correct parsing only process.argv[2] (the first positional token) or hooking into Commander's own parsed options rather than re-implementing flag matching by hand.

  2. Duplicated logic. The same --version/--help/NO_COLOR check is written twice — once in index.tsx as oscNonInteractive, and again inside terminalSupportsOSC() in terminal-color-detection.ts. These should share one helper so they can't drift out of sync.

  3. No new tests. The PR body says the existing 70 tests in terminal-color-detection.test.ts still pass, but no test was added asserting the new early-exit/NO_COLOR behavior in terminalSupportsOSC(), and no test touches the index.tsx gating at all. Given this is literally a regression-prevention fix, it needs a test that pins the new behavior down, including a case with -v/-h appearing as a non-top-level arg to make sure it doesn't over-trigger.

  4. The NO_COLOR plumbing through CliEnv/getCliEnv() is fine and matches existing patterns.

Worth porting in spirit, but I'd want the flag check narrowed to the top-level command token, the duplicate logic consolidated, and a couple of targeted tests before this goes in as-is.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:needs-work Right idea, not mergeable as written labels Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:needs-work Right idea, not mergeable as written

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CLI] OSC 11 background color query leaks into terminal prompt after freebuff --version (v0.2.38)

2 participants